<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
  <base href="/">
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0,user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <meta name="apple-mobile-web-app-capable" content="no">
  <meta name="format-detection" content="telephone=no">
  <title>登录页</title>
  <script src="static/js/cssrem.js"></script>
<link href="static/css/style.css" rel="stylesheet"></head>
<body class="bgwh">
  <div class="content">
    <div class="wrapper">
    <div class="login-wx-head auto photo100"><img src="${headimgurl}" alt></div>
    <div class="login-wx-tips">
      <p class="g3 f28">亲爱的万果用户：${phone}</p>
      <p class="g9 f28 pt20 mt10">您的微信账号已经绑定万果田园，是否直接登录？</p>
    </div>
    <div class="m20 pt10"></div>
    <div class="m20 pl10 pr10 pt20">
      <a id="forlogin" class="ui-login-btn ui-login-btn--primary db f32" href="javascript:;">确定</a>
      <p class="g-primary f28 m20 pt20 tc"><a class="g-primary mt20 dib" href="wap/login/toOtherLogin?forward=${forward}">用其他万果田园账号登录</a></p>
    </div>
    </div>
  </div>
  <input class="forward" type="hidden" value="${forward}">
<script src="static/js/layer_mobile/layer.js"></script>
<script type="text/javascript" src="static/js/app.js"></script>
<script src="https://cdn.bootcss.com/axios/0.16.2/axios.min.js"></script>
<script>
document.addEventListener('DOMContentLoaded',function(){
    var forlogin = document.querySelector('#forlogin');
    forlogin.addEventListener('click',function(){
    	var openid = getCookie("publicOpenid")
    	var formData = new FormData()
        formData.append('openid',openid)
        
  	  	submit('wap/login/wechatlogin',formData)
    })
  });
  
function getCookie(cookieName) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for(var i = 0; i < arrCookie.length; i++){
        var arr = arrCookie[i].split("=");
        if(cookieName == arr[0]){
            return arr[1];
        }
    }
    return "";
}

function submit(url,params){
	
	axios({
        method: 'post',
        url: url,
        data:params,
        headers: { 'X-Requested-With': 'XMLHttpRequest' }
    }).then(function (res) {
    	var state = res.data.result.state
    	var message = res.data.result.message
    	if(state!=1){
    		return layer.open({ content: message,skin:'msg',time: 2 })
    	}
   		var d = document.querySelector(".forward").value.trim()
   		if(d != ''){location.href=d}
    }).catch(function(err){
    	console.log(err)
    	layer.open({ content: '请求失败！',skin:'msg',time: 2 }) 
    })
}
  
</script>
</body>
</html>
